package io

import (
	"encoding/json"
	"fmt"
	"github.com/bitly/go-simplejson"
)

type servers1 struct {
	Version string    `json:"version"`
	Svs     []server1 `json:"server1"`
}

type server1 struct {
	ServerName string `json:"serverName"`
	ServerIP   string `json:"serverIP"`
}

func TestJson() {
	s := servers1{Version: "11"}
	arr := []server1{
		{ServerName: "local", ServerIP: "1001"},
		{ServerName: "local1", ServerIP: "1002"},
		{ServerName: "local2", ServerIP: "1003"},
	}
	s.Svs = arr

	data, _ := json.Marshal(s)
	fmt.Println(string(data))

	server := servers1{}
	jsonStr := "{\"version\":\"11\",\"server1\":[{\"serverName\":\"local\",\"serverIP\":\"1001\"},{\"serverName\":\"local1\",\"serverIP\":\"1002\"},{\"serverName\":\"local2\",\"serverIP\":\"1003\"}]}\n"
	json.Unmarshal([]byte(jsonStr), &server)
	fmt.Println(server)

	js, err := simplejson.NewJson([]byte(jsonStr))
	if err != nil {
		fmt.Println(err)
		return
	}

	j := js.Get("server1").GetIndex(0)
	map1, _ := j.Map()
	fmt.Println(map1)
}
